package com.hkts.naturalgas.workshop.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.utils.CustomPageUtils;
import com.hkts.naturalgas.utils.Result;
import com.hkts.naturalgas.utils.ResultUtil;
import com.hkts.naturalgas.workshop.entity.HktsWorkShop;
import com.hkts.naturalgas.workshop.service.IHktsWorkShopService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yck
 * @since 2021-10-08
 */
@RestController
@RequestMapping("/enviroment/hktsWorkShop")
public class HktsWorkShopController {
    private final Logger logger = LoggerFactory.getLogger(HktsWorkShopController.class);

    @Autowired
    public IHktsWorkShopService iHktsWorkShopService;

    /**
     * 分页查询数据
     *
     * @param page         分页信息
     * @param hktsWorkShop 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHktsWorkShopPageList")
    public Result<Object> getHontUserList(Page<HktsWorkShop> page, HktsWorkShop hktsWorkShop) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHktsWorkShopService.selectPage(page, hktsWorkShop)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hktsWorkShop 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsWorkShopSave")
    public Result<Object> hktsWorkShopSave(HktsWorkShop hktsWorkShop) {
        iHktsWorkShopService.saveOrUpdate(hktsWorkShop);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsWorkShopGetById")
    public Result<Object> hktsWorkShopGetById(String id) {
        HktsWorkShop byId = iHktsWorkShopService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsWorkShopDelete")
    public Result<Object> hontUserDelete(String id) {
        iHktsWorkShopService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsWorkShopBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHktsWorkShopService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    /** 功能描述:
    *
    * @return:
    * @Author: 杨春科
    * @Date: 2021-12-08 9:45
    * @Description //TODO
    */



}
